package com.fivestar.pmanager.web.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.fivestar.pmanager.constants.CommonConstants;
import com.fivestar.pmanager.core.base.BaseCommonParameterBean;
import com.fivestar.pmanager.system.domain.CommonParameterBean;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *  拦截器基类
 */
public class BaseInterceptor extends HandlerInterceptorAdapter
{

    protected String getRequestUrl(HttpServletRequest request)
    {
        String contentPath = request.getContextPath();
        String requestUrl = request.getRequestURI().substring(contentPath.length());
        if(requestUrl.contains("?"))
        {
            requestUrl = requestUrl.substring(0,requestUrl.lastIndexOf("?"));
        }
        return requestUrl;
    }


    protected BaseCommonParameterBean getCommonParameter(HttpSession session)
    {
        BaseCommonParameterBean commonParameterBean = (CommonParameterBean) session.getAttribute(
                CommonConstants.SESSION_KEY_COMMON_PARAMTER);
        if(commonParameterBean == null) return CommonParameterBean.defaultCommonParameter();
        return commonParameterBean;
    }
}
